<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        * {
            padding: 0;
            margin: 0;
        }

        li {
            list-style: none;
        }

        .wrap {
            width: 400px;
            margin: 0 auto;
            margin-top: 50px;
            position: relative;
        }

        .wrap img {
            width: 100%;
        }

        .box {
            line-height: 45px;
            display: flex;
            background-color: rgba(0, 0, 0, 0.4);
            position: absolute;
            right: 5px;
            bottom: 5px;
            padding: 5px;
            border-radius: 3px;
        }

        .box li {
            width: 10px;
            height: 10px;
            border-radius: 50%;
            margin: 0 10px;
            text-align: center;
            background-color: #fff;
            float: left;
        }

        .box .active {
            background-color: #6ff;
        }

        .content>div {
            height: 400px;
            text-align: center;
            line-height: 400px;
            display: none;
        }

        .content .active {
            display: block;
        }
    </style>
</head>

<body>
    <div class="wrap">
        <ul id="box" class="box">
            <li class="active"></li>
            <li></li>
            <li></li>
            <li></li>
        </ul>
        <div class="content">
            <div class="active"><img src="images/girlbig1.jpg" alt=""></div>
            <div><img src="images/girlbig2.jpg" alt=""></div>
            <div><img src="images/girlbig3.jpg" alt=""></div>
            <div><img src="images/girlbig4.jpg" alt=""></div>
        </div>
    </div>
</body>
<script>
    var box = document.getElementsByClassName("box")[0];
    var liList = box.getElementsByTagName("li");

    var content = document.getElementsByClassName("content")[0];
    var tabList = content.children;

    var index = 0; // 贯穿全局  用来控制 liList和tabList切换

    // 鼠标滑过  onmouseover
    // 鼠标滑出  onmouseout

    for (let i = 0; i < liList.length; i++) {
        let li = liList[i];
        // li.onclick = function () {
        //     // console.log(i, li);
        //     // clearInterval(timer);
        //     index = i;
        //     show(index);
        // }

        li.onmouseover = function () {
            console.log("onmouseover");
            index = i;
            clearInterval(timer);
            show(index);
        }

        li.onmouseout = function () {
            console.log("onmouseout");
            timer = setInterval(move, 4000);
        }
    }


    var timer = setInterval(move, 4000);

    function move() {
        index++;
        if (index == 4) {
            index = 0;
        }
        // console.log(index);
        show(index)
    }

    function show(i) {
        for (var j = 0; j < liList.length; j++) {
            liList[j].className = "";
            tabList[j].className = "";
        }

        liList[i].className = "active";
        tabList[i].className = "active";
    }






</script>

</html>